from pages.base_page import BasePage
from pages.checkout_page import CheckoutPage

class CartPage(BasePage):
    product_name_list_ele = {'type': 'xpath', 'value': '//table[@class="table table-bordered"]//a'}
    checkout_btn_ele = {'type': 'link', 'value': '结账'}  # 或者 'Checkout'

    def is_product_in_cart(self, keyword):
        names = self.get_texts(self.product_name_list_ele['value'], by=self.product_name_list_ele['type'])
        return any(keyword in name for name in names)

    def proceed_to_checkout(self):
        self.click_element(self.checkout_btn_ele['value'], by=self.checkout_btn_ele['type'])
        return CheckoutPage()
